package com.sqstudio.exercise.chapter3{
	
	import flash.events.Event;
	
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.objects.primitives.Cube;
	import org.papervision3d.view.BasicView;

	[SWF(width="800",height="600")]
	/**
	 *立方体 
	 * @author Nestor
	 * 
	 */	
	public class CubeExample extends BasicView
	{
		private var cube:Cube;
		public function CubeExample(viewportWidth:Number=800, viewportHeight:Number=600, scaleToStage:Boolean=true, interactive:Boolean=false, cameraType:String="Target")
		{
			super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
			stage.frameRate = 40;
			init();
			this.startRendering();
		}
		
		private function init():void{
			var red:ColorMaterial = new ColorMaterial(0xff0000);
			var bule:ColorMaterial = new ColorMaterial(0x00ff00);
			var green:ColorMaterial = new ColorMaterial(0x0000ff);
			var ml:MaterialsList = new MaterialsList();
			ml.addMaterial(red,"front");
			ml.addMaterial(red,"back");
			ml.addMaterial(bule,"left");
			ml.addMaterial(bule,"right");
			ml.addMaterial(green,"top");
			ml.addMaterial(green,"bottom");
//			ml.addMaterial(red,"all"); //指定所有面为 red
			this.cube = new Cube(ml,500,500,500,5,5,5);
//			this.cube = new Cube(ml,500,500,500,5,5,5,0,Cube.TOP); // 没有顶部
//			Cube.NONE =0
			scene.addChild(this.cube);
			this.cube.localRotationX=45;
		}
		
		override protected function onRenderTick(event:Event=null):void
		{
			this.cube.localRotationY ++;
			super.onRenderTick(event);
		}
	}
}